package com.shgsh.server.utils;

import com.alibaba.fastjson.JSON;
import com.shgsh.server.model.IMMessage;
import com.shgsh.server.model.IMSignal;
import com.shgsh.server.model.IMUser;
import org.apache.shiro.crypto.hash.Sha512Hash;


import java.util.Random;

/**
 * Created by pcc on 2015/8/13.
 */
public class SecurityUtil {
    public static String ps = "ps";

    /**
     * 密码sha加密
     * @param username
     * @param password
     * @return
     */
    public static String generatePassword(String username,String password){
        String passwordHash = new Sha512Hash(password, username + ps, 99).toString();
        return passwordHash;
    }

    /**
     * 随机生成6位随机数的密钥钥匙
     * @return
     */
    public static String randomStrKey(){
        Random r = new Random();
        Double d = r.nextDouble();
        String s = d + "";
        s=s.substring(3,3+6);
        return s;
    }
    public static void main(String[] args){

        IMUser user = new IMUser();
        user.setUsername("i");
        user.setActiveState("1");
        user.setId("1");
        user.setMessageIdList("");
        user.setLastEnterTime("2015-08-03");
        user.setOperation("");
        System.out.println(JSON.toJSON(user));

        user.setUsername("a");
        user.setActiveState("1");
        user.setId("2");
        user.setMessageIdList("");
        user.setLastEnterTime("2015-08-03");
        user.setOperation("");
        System.out.println(JSON.toJSON(user));


        IMSignal signal = new IMSignal();
        signal.setUserId("1");
        signal.setIpAndPort("");
        signal.setSessionEncryptKey("");
        System.out.println(JSON.toJSON(signal));

        signal.setUserId("2");
        signal.setIpAndPort("");
        signal.setSessionEncryptKey("");
        System.out.println(JSON.toJSON(signal));

        IMMessage message = new IMMessage();
        message.setId("1");
        message.setReceiverId("2");
        message.setSendId("1");
        message.setContent("hello");
        message.setSendTime("00:00:00");
        System.out.println(JSON.toJSON(message));


    }
}
